var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0}), (o.gameServer = o.CustomPlayerStatus = void 0);
var n,
    r = t("Platforms"),
    a = t("PlatformCtrl_native");
(function (t) {
    (t[(t["未准备"] = 0)] = "未准备"), (t[(t["已准备"] = 1)] = "已准备");
})((n = o.CustomPlayerStatus || (o.CustomPlayerStatus = {})));
var i = (function () {
    function t() {}
    return (
        (t.prototype.update = function (t, e) {
            (e ? console.error : console.log)(t), this.onUpdate && this.onUpdate(t, e);
        }),
        (t.prototype.init = function (t, e, o, n) {
            (this.gameId = t),
                (this.secretKey = e),
                (this.url = o),
                (this.matchCode = n),
                (this.loginStatus = "未登录");
        }),
        (t.prototype.login = function (t) {
            var e = this;
            switch (this.loginStatus) {
                case "未登录":
                    (this.loginStatus = "登录中"), console.log("openId=" + r.default.userStorage.openId);
                    var o = function (o) {
                        MGOBE.Listener.init(
                            {openId: r.default.userStorage.openId, gameId: e.gameId, secretKey: e.secretKey},
                            {
                                url: e.url,
                                reconnectMaxTimes: 5,
                                reconnectInterval: 1e3,
                                resendInterval: 1e3,
                                resendTimeout: 1e4,
                                cacertNativeUrl: o
                            },
                            function (o) {
                                e.checkErrCode("连接服务器", o.code)
                                    ? (console.log("玩家ID=" + MGOBE.Player.id),
                                      (e.me = {
                                          id: MGOBE.Player.id,
                                          name: r.default.userStorage.get昵称(),
                                          customProfile: r.default.userStorage.encodeCustomProfile(),
                                          在线: c
                                      }),
                                      (e.room = new MGOBE.Room()),
                                      e.room.initRoom(),
                                      e.玩家可能匹配一半退出游戏所以进来后先取消一下(),
                                      e.进来后先看看之前是否有已进入的房间如果有就先退一下房(function (o) {
                                          o && e.加各种监听(), (e.loginStatus = o ? "登录成功" : "未登录"), t && t(o);
                                      }))
                                    : (r.default.platformCtrl.toast("连接服务器失败 " + o.code),
                                      (e.loginStatus = "未登录"),
                                      t && t(!1));
                            }
                        );
                    };
                    r.default.platformCtrl instanceof a.default
                        ? r.default.platformCtrl.getAssetPath("1st", "cacert", o)
                        : o();
                    break;
                case "登录中":
                    break;
                case "登录成功":
                    t && t(!0);
            }
        }),
        (t.prototype.玩家可能匹配一半退出游戏所以进来后先取消一下 = function () {
            this.room.cancelPlayerMatch({matchType: MGOBE.ENUM.MatchType.PLAYER_COMPLEX}, function (t) {});
        }),
        (t.prototype.进来后先看看之前是否有已进入的房间如果有就先退一下房 = function (t) {
            var e = this;
            MGOBE.Room.getMyRoom(function (o) {
                e.checkErrCode("查询玩家所在的房间信息", o.code, !1) && o.data && o.data.roomInfo
                    ? e.room.leaveRoom({}, function (o) {
                          e.checkErrCode("退出房间", o.code, !1), t && t(!0);
                      })
                    : t && t(!0);
            });
        }),
        (t.prototype.加各种监听 = function () {
            var t = this;
            MGOBE.Listener.add(this.room),
                (MGOBE.Room.onMatch = function (e) {
                    (e.data && t.checkErrCode("监听匹配结果", e.data.errCode, !1)) || t.update("匹配失败", !0);
                }),
                (this.room.onDismissRoom = function (t) {
                    console.log("room.onDismissRoom", JSON.stringify(t));
                }),
                (this.room.onChangeRoom = function (t) {
                    console.log("room.onChangeRoom", JSON.stringify(t));
                }),
                (this.room.onRemovePlayer = function (t) {
                    console.log("room.onRemovePlayer", JSON.stringify(t));
                }),
                (this.room.onRecvFromClient = function (e) {
                    e && e.data && t.onRecvFromClient && t.onRecvFromClient(e.data.sendPlayerId, e.data.msg);
                }),
                (this.room.onStartFrameSync = function (t) {
                    console.log("room.onStartFrameSync", JSON.stringify(t));
                }),
                (this.room.onStopFrameSync = function (t) {
                    console.log("room.onStopFrameSync", JSON.stringify(t));
                }),
                (this.room.onRecvFrame = function (t) {
                    console.log("room.onRecvFrame", JSON.stringify(t));
                }),
                (this.room.onUpdate = function () {
                    if (t.room.roomInfo && t.room.roomInfo.playerList) {
                        for (var e = null, o = null, n = 0, r = t.room.roomInfo.playerList; n < r.length; n++) {
                            var a = r[n];
                            a.id == MGOBE.Player.id ? (e = a) : ((o = a), (t.创建房间等待好友 = !1));
                        }
                        var i = "";
                        if (t.self)
                            e
                                ? (i += t.playerUpdated(t.self, e))
                                : ((t.self = null), (o = null), (i += "，我方离开房间"));
                        else if (e) {
                            for (var s in e) t.me[s] = e[s];
                            (t.self = t.me), (i += "，我方进入房间");
                        }
                        t.self && (t.self.在线() || (t.self = null)),
                            t.opponent
                                ? o
                                    ? (i += t.playerUpdated(t.opponent, o))
                                    : ((t.opponent = null), (i += "，对方离开房间"))
                                : o && ((t.opponent = o), (t.opponent.在线 = c), (i += "，对方进入房间")),
                            t.opponent && (t.opponent.在线() || (t.opponent = null)),
                            i && t.update(i.substr(1), !1);
                    }
                });
        }),
        (t.prototype.playerUpdated = function (t, e) {
            var o = "";
            if (
                (t.customPlayerStatus != e.customPlayerStatus &&
                    (o += "，customPlayerStatus " + t.customPlayerStatus + " -> " + e.customPlayerStatus),
                t.commonNetworkState != e.commonNetworkState &&
                    (o += "，commonNetworkState " + t.commonNetworkState + " -> " + e.commonNetworkState),
                t.relayNetworkState != e.relayNetworkState &&
                    (o += "，relayNetworkState " + t.relayNetworkState + " -> " + e.relayNetworkState),
                o)
            )
                for (var n in e) t[n] = e[n];
            return o;
        }),
        (t.prototype.matchPlayers = function () {
            var t = this;
            this.room.matchPlayers(
                {
                    playerInfo: {
                        name: r.default.userStorage.get昵称(),
                        customPlayerStatus: n.未准备,
                        customProfile: r.default.userStorage.encodeCustomProfile(),
                        matchAttributes: null
                    },
                    matchCode: this.matchCode
                },
                function (e) {
                    t.checkErrCode("匹配玩家", e.code) || t.update("匹配失败", !0);
                }
            );
        }),
        (t.prototype.cancelPlayerMatch = function (t) {
            this.room.cancelPlayerMatch({matchType: MGOBE.ENUM.MatchType.PLAYER_COMPLEX}, function (e) {
                t && t();
            });
        }),
        (t.prototype.createRoom = function (t) {
            var e = this;
            (this.创建房间等待好友 = !0),
                this.room.createRoom(
                    {
                        roomName: "去年买了个房",
                        maxPlayers: 2,
                        roomType: "1V1",
                        isPrivate: !1,
                        customProperties: "WAIT",
                        playerInfo: {
                            name: r.default.userStorage.get昵称(),
                            customPlayerStatus: n.未准备,
                            customProfile: r.default.userStorage.encodeCustomProfile()
                        }
                    },
                    function (o) {
                        if (e.checkErrCode("创建房间", o.code) && o.data && o.data.roomInfo)
                            return (e.roomId = o.data.roomInfo.id), void (t && t(!0));
                        t && t(!1);
                    }
                );
        }),
        (t.prototype.leaveRoomAndJoinRoom = function (t, e) {
            var o = this;
            this.roomId
                ? this.leaveRoom(function () {
                      o.joinRoom(t, e);
                  })
                : this.joinRoom(t, e);
        }),
        (t.prototype.joinRoom = function (t, e) {
            var o = this;
            this.room.initRoom({id: t}),
                this.room.joinRoom(
                    {
                        playerInfo: {
                            name: r.default.userStorage.get昵称(),
                            customPlayerStatus: n.未准备,
                            customProfile: r.default.userStorage.encodeCustomProfile()
                        }
                    },
                    function (t) {
                        o.checkErrCode("加入房间", t.code) ? e && e(!0) : e && e(!1);
                    }
                );
        }),
        (t.prototype.leaveRoom = function (t) {
            (this.roomId = null),
                this.room
                    ? this.room.leaveRoom({}, function (e) {
                          t && t();
                      })
                    : t && t();
        }),
        (t.prototype.changeCustomPlayerStatus = function (t) {
            var e = this;
            this.room &&
                this.room.changeCustomPlayerStatus({customPlayerStatus: t}, function (t) {
                    e.checkErrCode("修改玩家自定义状态", t.code, !1);
                });
        }),
        (t.prototype.sendToClient = function (t) {
            var e = this;
            this.room.sendToClient(
                {recvType: MGOBE.ENUM.RecvType.ROOM_ALL, recvPlayerList: null, msg: t},
                function (t) {
                    e.checkErrCode("发消息", t.code, !1);
                }
            );
        }),
        (t.prototype.checkErrCode = function (t, e, o) {
            if ((void 0 === o && (o = !0), e == MGOBE.ErrCode.EC_OK)) return !0;
            if (o) {
                var n = s[e] + " " + e;
                console.error(t + " " + n), r.default.platformCtrl.toast(n);
            }
            return !1;
        }),
        t
    );
})();
o.gameServer = new i();
var s = {
        0: "返回成功",
        1: "请求包格式错误",
        2: "非法命令字",
        3: "参数错误",
        4: "服务器内部错误",
        5: "后端超时错误",
        6: "服务器繁忙",
        7: "没有权限请求",
        200: "命令字无效错误",
        201: "获取 Token 失败",
        202: "Token 即将过期",
        203: "Token 无效或过期",
        204: "PUSH 序列化包失败",
        205: "登录用户中心回包解析出错",
        206: "查找连接信息出错",
        207: "获取 Relay 的 RS_IP 或 RS_PORT 出错",
        208: "添加 COMM 连接信息失败",
        209: "添加心跳连接信息失败",
        210: "添加 Relay 连接信息失败",
        211: "心跳包解析出错",
        212: "获取 COMM 连接信息失效",
        213: "获取 RELAY 连接信息失效",
        214: "连接信息为空",
        215: "用户已经登录，不能重复登录",
        216: "转发 SVR 名字错误，不是 relay_svr 或 state_svr",
        10000: "game 不存在",
        10001: "查询 secret_key 失败",
        10002: "sign校验失败",
        10003: "重复请求",
        10004: "timestamp 非法",
        10005: "查询用户信息失败",
        10006: "新增用户信息失败",
        10007: "查询 game 信息失败",
        10008: "用户记录数不正确",
        10009: "查询 Token 失败",
        10010: "Token 不存在",
        10011: "Token 非法",
        10012: "清除 Token 缓存失败",
        10013: "获取分布式锁失败",
        10014: "释放分布式锁失败",
        10015: "保存 Token 缓存失败",
        10016: "PLAYER GAME OUT OF SERVICE",
        20000: "创建房间无权限",
        20001: "销毁房间无权限",
        20002: "无权限加入房间",
        20003: "无踢人权限",
        20004: "无修改房间属性权限",
        20005: "无解散房间权限",
        20006: "无踢出自己权限",
        20007: "检查登录失败",
        20008: "被踢玩家不在房间中",
        20010: "用户已经在房间内，不能操作创建房间、加房等操作",
        20011: "用户目前不在房间内，不能操作更改房间属性、踢人等操作",
        20012: "房间内用户数已经达到最大人数不能再加入了",
        20013: "房间不允许加入用户",
        20014: "最大用户数值设置非法",
        20015: "创建房间失败",
        20016: "用户在房间中掉线，不能开始游戏等操作",
        20017: "页号、页数大小参数不合法，可能实际大小没这么大",
        20050: "查询用户信息失败",
        20051: "获取房间信息失败",
        20052: "修改房主失败",
        20053: "房间数量超过限制",
        "-20052": "ROOM REMOVE REDIS PLAYER ROOM MATCH ERR",
        "-20053": "ROOM REMOVE REDIS ROOM INFO ERR",
        "-20054": "ROOM REDIS UPDATE ERR",
        "-20055": "ROOM REDIS GET LOCK ERR",
        "-20056": "ROOM REDIS CHECK LOCK ERR",
        "-20057": "ROOM REDIS DEL LOCK ERR",
        20060: "查询用户信息失败",
        20061: "游戏信息失败",
        20062: "用户信息不存在",
        20063: "游戏信息不存在",
        "-20064": "ROOM HISTORY INFO INSERT ERR",
        20065: "查询不到 accessRegion 信息",
        20066: "查询地域信息失败",
        20070: "玩家信息操作繁忙，请重试",
        20080: "房间信息不存在",
        20090: "ctrlsvr 分配 relaysvr 失败",
        20100: "房间 teamId 无效",
        20101: "房间团队人员已满",
        "-20200": "ROOM ALLOCATE SERVICE FAIL",
        30000: "匹配失败，无任何房间",
        30001: "匹配超时",
        30002: "匹配逻辑错误",
        30010: "匹配失败",
        30011: "用户已经在匹配中",
        30012: "用户不在匹配状态",
        30013: "获取匹配信息失败",
        30014: "更新匹配信息失败",
        30015: "取消匹配失败",
        30016: "查询匹配队列信息失败",
        30041: "匹配创建房间失败",
        30042: "匹配加入房间失败",
        30043: "匹配无效参数",
        30044: "匹配小组人数超过队伍上限",
        30045: "匹配小组中玩家 ID 重复",
        30050: "匹配创房 有玩家已经在房间中",
        30100: "查询用户信息失败",
        30101: "用户信息不存在",
        30102: "查询游戏信息失败",
        30103: "游戏信息不存在",
        30104: "查询大区信息失败",
        30105: "无大区信息",
        30106: "团队匹配失败",
        30107: "匹配规则不可用",
        30108: "匹配参数不完整",
        30109: "匹配规则不存在",
        30110: "匹配规则获取属性匹配区间失败",
        30111: "匹配规则算法错误",
        30112: "匹配获取玩家属性失败",
        30113: "匹配获取队伍属性失败",
        30114: "MATCH NONE TEAM TYPE FIT",
        30115: "MATCH TEAM TYPE INVALID",
        30116: "MATCH PLAYER ATTR NOT FOUND",
        30117: "MATCH REQUEST ID NOT EXIST",
        30118: "MATCH REQUEST ID IS EXIST",
        30119: "MATCH TEAM MATCH FAIL",
        30120: "MATCH ROBOT GROUP NOT RIGHT",
        30121: "MATCH ROBOT TEAM NOT RIGHT",
        "-30150": "MATCH INNER LOGIC ERR",
        "-30160": "MATCH INNER PARAMS ERR",
        "-30170": "MATCH ROOM INNER ADD NODE ERR",
        "-30171": "MATCH ROOM INNER DEL NODE ERR",
        "-30172": "MATCH RESULT TYPE NOT GSE",
        30173: "MATCH REQUEST CANCELED",
        40000: "重复创建",
        40001: "服务不存在",
        40002: "data 长度超限制",
        40003: "成员已存在",
        40004: "成员不存在",
        40005: "状态异常",
        40006: "帧率非法",
        40007: "开局状态下，G 不允许修改帧率",
        40008: "没任何成员",
        40009: "自定义扩展服务（gamesvr）未开通",
        40010: "请求分配 pod 失败",
        40011: "无可用的 pod",
        40012: "查询帧缓存失败",
        40015: "共享内存缓存错误",
        40016: "redis 缓存错误",
        40018: "通知 relayworker 失败",
        40019: "重置房间对局失败",
        40020: "清理房间对局数据失败",
        40100: "没权限，401开头是权限相关错误",
        40200: "通知自定义服务 gamesvr 失败， 402开头，是自定义 gamesvr 相关的错误",
        40201: "转发到自定义逻辑 svr 失败",
        40202: "转发到 client-sdk 失败",
        40203: "实时服务器未找到房间信息（一般为重启导致）",
        70000: "队组操作失败",
        70001: "队组名称参数错误",
        70002: "队组类型参数错误",
        70003: "队组自定义属性参数错误",
        70004: "队组玩家名称参数错误",
        70005: "队组玩家自定义状态参数错误",
        70006: "队组玩家自定义属性参数错误",
        70007: "无权限修改队组队长",
        70008: "队组id参数错误",
        70009: "无效的修改选项",
        70010: "队组 owner 参数错误",
        70011: "玩家已经在队组中",
        70012: "玩家不在该队组中",
        70013: "被移除的玩家 ID 为空",
        70014: "没有权限移除玩家",
        70015: "队组接收消息类型参数错误",
        70016: "队组接收消息的玩家中存在不在队组中的玩家",
        70017: "消息长度超过限制",
        70018: "最大玩家数量参数错误",
        70020: "玩家不在队组中不允许操作",
        70022: "队组禁止玩家加入",
        70023: "发送消息频率达到限制",
        70024: "对组中人数超过限制",
        70025: "玩家加入的对组个数超过限制",
        70026: "队组不存在",
        60000: "业务参数错误",
        60001: "玩法协议版本号错误",
        60002: "玩法协议规则类型错误",
        60003: "玩法协议规则表达式错误",
        60004: "玩法协议规则团队表达式错误",
        60020: "INVALID PARAMS MSGQ ENCODE",
        60021: "INVALID PARAMS MSGQ DECODE",
        61000: "参数错误 game_id",
        61001: "参数错误 player_info",
        61002: "参数错误 max_players",
        61003: "参数错误 room_type",
        61004: "参数错误 player_id",
        61005: "参数错误 match_type",
        61006: "参数错误 match_code",
        61007: "参数错误 open_id",
        61008: "参数错误 platform",
        61009: "参数错误 timestamp",
        61010: "参数错误 sign",
        61011: "参数错误 nonce",
        61012: "参数错误 token",
        61013: "参数错误 network_state",
        61014: "参数错误 room_name",
        61015: "参数错误 create_room_type",
        61016: "参数错误 device_id",
        61017: "参数错误 page_no",
        61018: "参数错误 page_size",
        61019: "参数错误 player list",
        61020: "参数错误 message",
        61021: "参数错误 change_room_option_list",
        61022: "INVALID PARAMS REGION",
        61023: "INVALID PARAMS OWNER",
        61024: "INVALID PARAMS OWNER OPEN ID",
        61026: "INVALID PARAMS OPEN ID DUPLICATE",
        61027: "INVALID PARAMS ROOM CREATE TYPE",
        "-1000": "MYSPP SYSTEM ERR",
        "-66000": "REDIS KEY NOT EXIST",
        "-66001": "REDIS SET OP ERR",
        "-66002": "REDIS GET OP ERR",
        "-66003": "REDIS DEL OP ERR",
        "-66004": "REDIS EXPIRE OP ERR",
        "-66005": "REDIS LOCK OP ERR",
        "-66006": "REDIS LOCK ALREADY EXIST",
        "-66020": "REDIS LIST OP ERR",
        "-66021": "REDIS LIST POP EMPTY",
        "-66022": "REDIS POOL GET INSTANCE FAIL",
        "-66023": "REDIS SET IS EMPTY",
        "-66024": "REDIS OP INVALID PARAMS",
        "-66100": "MYSQL NO ROW FOUND",
        "-66101": "MYSQL MULTI ROW FOUND",
        "-66102": "MYSQL INSERT FAIL",
        "-66103": "MYSQL DELETE FAIL",
        "-66104": "MYSQL UPDATE FAIL",
        "-66105": "MYSQL QUERYS FAIL",
        "-66200": "PB SERIALIZE TO STR ERR",
        "-66201": "PB PARSE FROM STR ERR",
        "-66210": "DATA FORMAT ERR",
        "-66211": "JSON FORMAT ERR",
        "-66212": "JSON PLAY MODE FORMAT ERR",
        "-66213": "JSON PLAY MODE PARISE ERR",
        "-66601": "INVALID PARAMS RECORE ID",
        "-66700": "HASHID ERR",
        "-66701": "HASHID ENCODE ERR",
        "-66702": "HASHID DECODE ERR",
        "-66801": "CONF ROOM ID BUCKET ERR",
        90001: "消息发送失败",
        90002: "SDK 未初始化",
        90003: "消息响应超时",
        90004: "登录态错误",
        90005: "帧同步鉴权错误",
        90006: "网络错误",
        90007: "Socket 断开",
        90008: "无房间",
        90009: "编码失败",
        90010: "参数错误"
    },
    c = function () {
        return this.commonNetworkState == MGOBE.types.NetworkState.COMMON_ONLINE;
    };
